#!/usr/bin/env python

import urllib2
import re

class Whois(object):
    def __init__(self, ip):
        self.ip = ip
        ua = 'Mozilla/5.0 (compatible; Konqueror/3.5.8; Linux)'
        self.h = {'User-Agent': ua}

    def ispInfo(self):
        site = "http://www.ip-adress.com/whois/%s" %(self.ip)
        print "\n[*] Cetting information..."
        f = urllib2.urlopen(urllib2.Request(site, headers=self.h)).read()
        isp = re.findall("<b>\d+.\d+.\d+.\d+ (ISP:)</b><br>\s+([A-Za-z]+[ ]+[A-Za-z]+[ ]?[A-Za-z])</div", f)
        location = re.findall("<b>\d+.\d+.\d+.\d+ (server location:)</b><br>([A-Za-z]+[ ]+[A-Za-z]+[ ]+[A-Za-z]+[ ]?[A-Za-z]+[ ]?[A-Za-z]+)", f)
        for i in location:
            print "\n%s: %s" % (i[0], i[1])
        for i in isp:
            print "%s %s" % (i[0], i[1])
        coordinates = re.findall("loadmap\(([-]?[+]?[0-9]+.[0-9]+,[-]?[+]?[0-9]+.[0-9]+)", f)
        self.cor = str(coordinates).replace("['","").replace("']","")
        print "\n[!] Getting the rest of the information please wait..."

    def whoisInfo(self):#thnx irenicus you made my life way more easier with this!
        site = 'http://www.proxys.com.ar/index.php?act=whois&ip=%s' % (self.ip)
        source = (urllib2.urlopen(site)).read()
        pat = re.compile(r'<br />([\s|\w|\W]+)<br />\s+</td></tr>')
        whois = pat.findall(source)
        for i in whois:
            print i.replace('<br />', '')
        print "\n[GOOGLE MAP LINK] http://maps.google.com/maps?ie=%s" % (self.cor)

if __name__ == '__main__':
    ipaddress = raw_input('Enter a hostname: ')
    w = Whois(ipaddress)
    w.ispInfo()
    w.whoisInfo()
